package com.chen.recruit.controller;

import com.chen.recruit.common.annotation.Log;
import com.chen.recruit.common.api.CommonResult;
import com.chen.recruit.common.enums.BusinessType;
import com.chen.recruit.common.valid.AddGroup;
import com.chen.recruit.common.valid.UpdateGroup;
import com.chen.recruit.domain.PostClassify;
import com.chen.recruit.domain.model.PageQuery;
import lombok.RequiredArgsConstructor;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.chen.recruit.service.PostClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "岗位分类管理 PostClassifyController")
@RequiredArgsConstructor
@RestController
@RequestMapping("/recruit/post-classify")
public class PostClassifyController {

    private final PostClassifyService postClassifyService;

    @ApiOperation("新增岗位分类")
    @SaCheckPermission("recruit:post-classify:add")
    @Log(module = "招聘管理-岗位分类", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@Validated(AddGroup.class) @RequestBody PostClassify postClassify) {
        return postClassifyService.addPostClassify(postClassify);
    }

    @ApiOperation("删除岗位分类")
    @SaCheckPermission("recruit:post-classify:delete")
    @Log(module = "招聘管理-岗位分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public CommonResult delete(@PathVariable Integer id) {
        return postClassifyService.deletePostClassifyById(id);
    }

    @ApiOperation("更新岗位分类")
    @SaCheckPermission("recruit:post-classify:update")
    @Log(module = "招聘管理-岗位分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult update(@Validated(UpdateGroup.class) @RequestBody PostClassify postClassify) {
        return postClassifyService.updatePostClassify(postClassify);
    }

    @ApiOperation("获取岗位分类详细信息")
    @SaCheckPermission("recruit:post-classify:update")
    @GetMapping("/{id}")
    public CommonResult getInfo(@PathVariable Integer id) {
        return CommonResult.success(postClassifyService.getById(id));
    }

    @ApiOperation("查询岗位分类列表")
    @SaCheckPermission("recruit:post-classify:list")
    @GetMapping("/list")
    public CommonResult list(PostClassify params, PageQuery pageQuery) {
        return CommonResult.success(postClassifyService.getPostClassifyList(params, pageQuery));
    }

}
